﻿@if (Rows <= 1)
{
    <input class="@ClassString" type="@Type" disabled="@Disabled" @bind-value="@Value" @oninput="@OnInputChangeAsync" />
}
else
{
    <textarea class="@ClassString" rows="@Rows" disabled="@Disabled" @oninput="@OnInputChange">@Value</textarea>
}

@code {
    #region Parameter
    /// <summary>
    /// 行数
    /// </summary>
    [Parameter]
    public int Rows { get; set; } = 1;

    /// <summary>
    /// 禁用状态
    /// </summary>
    [Parameter]
    public bool Disabled { get; set; }

    /// <summary>
    /// 自定义Class
    /// </summary>
    [Parameter]
    public string Class { get; set; } = string.Empty;

    /// <summary>
    /// 类型
    /// </summary>
    [Parameter]
    public string Type { get; set; } = "text";

    /// <summary>
    /// 值
    /// </summary>
    [Parameter]
    public string Value { get; set; }

    /// <summary>
    /// 值更新
    /// </summary>
    [Parameter]
    public EventCallback<string> ValueChanged { get; set; }
    /// <summary>
    /// 值更改
    /// </summary>
    [Parameter]
    public EventCallback<ChangeEventArgs> OnInputChange { get; set; }
    #endregion
    #region 属性
    /// <summary>
    /// Class字符串
    /// </summary>
    public string ClassString
    {
        get
        {
            var result = "m_form_input";
            if (!string.IsNullOrWhiteSpace(Class))
            {
                result += $" {Class}";
            }
            return result;
        }
    }
    #endregion
    #region 方法
    /// <summary>
    /// 输入更改
    /// </summary>
    /// <param name="eventArgs"></param>
    /// <returns></returns>
    public async Task OnInputChangeAsync(ChangeEventArgs eventArgs)
    {
        await ValueChanged.InvokeAsync(eventArgs.Value.ToString());
        await OnInputChange.InvokeAsync(eventArgs);
    }
    #endregion
}